﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyWeb.Data;
using MyWeb.Common;
using MyWeb.Business;

public partial class ThemUsers : System.Web.UI.Page
{
    private tblUSER_PROFILEInfo userProfile = new tblUSER_PROFILEInfo();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["Username"] != null)
            {
                lblCreateUser.Text = Session["Username"].ToString();
                lblUserEdit.Text = Session["Username"].ToString();
                string dtnow = DateTime.Today.ToString("dd/MM/yyyy");
                lblCreateDate.Text = dtnow;
                lblEditDate.Text = dtnow;
                lblLastLogin.Text = dtnow;

            } else
            {
                Response.Redirect("~/Login12.aspx");
            }


        }


    }
    protected void lblUpdate_Click(object sender, EventArgs e)
    {
        #region[TestInput]

        if (txtUserName.Text.Trim().Equals(""))
        {
            WebMsgBox.Show("Bạn chưa nhập Tên đăng nhập!");
            txtUserName.Focus();
            return;
        }
        if (txtPassWord.Text.Trim().Equals(""))
        {
            WebMsgBox.Show("Bạn chưa nhập Mật khẩu");
            txtPassWord.Focus();
            return;
        }
        #endregion

        try
        {
            userProfile.USERNAME = txtUserName.Text;
            userProfile.PASSWORD = StringClass.Encrypt(txtPassWord.Text);
            userProfile.EMAIL = txtEmai.Text;
            userProfile.LASTLOGIN_DATE = lblLastLogin.Text;
            userProfile.CREATE_USER = lblCreateUser.Text;
            userProfile.CREATE_DATE = lblCreateDate.Text;
            userProfile.USER_EDIT = lblUserEdit.Text;
            userProfile.DATE_EDIT = lblEditDate.Text;
            userProfile.STATUS = ddlStatus.SelectedValue;

            tblUSER_PROFILEService.tblUSER_PROFILE_Insert(userProfile);
            Response.Redirect("~/ThongTinTaiKhoan.aspx");
        }
        catch (Exception)
        {

            WebMsgBox.Show("Insert Error!");
        }
    }
}